//
//  LBLinkedContentViewTittleCell.m
//  LBTwoLinkedScrollingCollectionView
//
//  Created by mac on 2024/6/25.
//

#import "LBLinkedContentViewTittleCell.h"

@interface LBLinkedContentViewTittleCell ()

@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation LBLinkedContentViewTittleCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI
{
    [self.contentView addSubview:self.titleLabel];
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    if (selected) {
        self.titleLabel.textColor = [UIColor redColor];
        self.contentView.backgroundColor = [UIColor greenColor];
    } else {
        self.titleLabel.textColor = [UIColor cyanColor];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }
}

- (void)updateWithIndexPath:(NSIndexPath *)indexPath
{
    NSString *title = [NSString stringWithFormat:@"%ld", indexPath.item];
    self.titleLabel.text = title;
}

#pragma mark - lazy load

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
        _titleLabel.textColor = [UIColor cyanColor];
        _titleLabel.font = [UIFont systemFontOfSize:17];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

@end
